﻿using Caliburn.Micro;
using SS.Common.Utilities;
using SS.WPF.Framework.Localization;

namespace SS.WPF.Framework.ValidationRule
{
    using System.Globalization;
    using System.Windows.Controls;

    public class PathExistValidationRule : ValidationRule, IValidationRuleCommon
    {
        private bool _isEnable { get; set; }
        public PathExistValidationRule()
        {
            _isEnable = true;
        }

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (!_isEnable)
            {
                return ValidationResult.ValidResult;
            }
            else
            {
                var path = value as string;
                 //|| path.Contains("...")
                
                if (path == null)
                {
                    return new ValidationResult(false, IoC.Get<TranslationManager>().Translate("FileNotSpecify") as string);
                }

                var pa = PathHelper.GetAppPath(path);
                if (!System.IO.File.Exists(pa))
                {
                    return new ValidationResult(false, IoC.Get<TranslationManager>().Translate("FileNotExist") as string);                    
                }
                
                return ValidationResult.ValidResult;
            }
        }


        public bool IsEnabled
        {
            get
            {
                return this._isEnable;
            }
            set
            {
                this._isEnable = value;
            }
        }
    }
}
